<?php $kosaricaHelper = $this->getHelper('Kosarica'); ?>
<?php $strankaSession = new Zend_Session_Namespace('Store_Stranke'); ?>
<?php $messagesHelper = $this->getHelper('Messages'); ?>
<?php $configHelper = $this->getHelper('Config'); ?>
<div id="view-content">
    <?php echo $messagesHelper->formatMessage($strankaSession->error, 'error'); ?>
    <?php $strankaSession->error = null; ?>
    <?php $kosarica = $kosaricaHelper->getKosarica(); ?>
    <?php if ($kosarica == null): ?>
    <p><?php echo "V košarici še ni izdelkov." ?></p>
        <?php return; ?>
    <?php endif; ?>
    <table id="kosarica-grid" class="table">
       
        <tr>
            <th>Ime izdelka:</th>  <th>Količina:</th> <th>Cena izdelka:</th><th>Skupna cena:</th><th></th>
        </tr>

        <?php foreach ($kosarica as $kosara): ?>
         <tr>
    <td><?php echo $kosara['izdelek']->getIme();  ?> 
                   <b> <FONT color=Red><?php if ($kosara['kolicina']>$kosara['izdelek']->getZaloga()){
                echo "MAXIMALNA KOLIČINA IZDELKA JE :". $kosara['izdelek']->getZaloga();
                }?></td></b></FONT>
                <td><form method="POST" action="<?php echo $this->url(array('controller' => 'kosarica', 'action' => 'posodobi-kolicino')) ?>">
                        <input type="text" value="<?php echo $kosara['kolicina']; ?>" name="qty" />
                        <input type="hidden" value="<?php echo $kosara['izdelek']->getIdProdukt() ?>" name="idprodukt" />
                        <input type="submit" class="button btn-danger" value="Posodobi" />
                    </form></td>
                <td><?php echo number_format($kosara['izdelek']->getCena(),2);?> <?php echo $configHelper->getCurrencySymbol() ?></td>
               <td> <?php if ($kosara['kolicina']>$kosara['izdelek']->getZaloga()){
                    echo number_format($kosara['izdelek']->getCena() *$kosara['izdelek']->getZaloga(),2);echo $configHelper->getCurrencySymbol();
                } else {
                    
                     echo number_format($kosara['izdelek']->getCena() * $kosara['kolicina'],2);echo $configHelper->getCurrencySymbol();
                }
                ?></td>
                <td><?php
                    $form = new Application_Form_IdForm();
                    $form->setAction($this->url(array('controller' => 'kosarica', 'action' => 'odstrani-izdelek')));
                    $form->setDefaults(array('id' => $kosara['izdelek']->getIdProdukt()));
                    $form->getElement('submit')->setLabel('Odstrani');
                    echo $form;
                ?></td>
         </tr>
        <?php endforeach; ?>
                    <tr>
            
        </tr>
            <?php $koncni=0 ?>
             <?php foreach ($kosarica as $kosara): ?>
       <tr> <?php if ($kosara['kolicina']>$kosara['izdelek']->getZaloga()){
                    
                    $koncni += $kosara['izdelek']->getCena() * $kosara['izdelek']->getZaloga();
                } else {
                    
                     $koncni += $kosara['izdelek']->getCena() * $kosara['kolicina'];
                }
          
           
               ?> </tr>
        <?php endforeach; ?>
                 <td><b>Končen znesek nakupa:</b></td> <td></td> <td></td>
        <td colspan="5"><div style="float: right;width: 345px"><?php echo number_format($koncni,2)?> <?php echo $configHelper->getCurrencySymbol() ?></div></td>
         <tr>
            
    </table>

    <button class="button btn-primary" onclick="javascript:window.location.href='<?php echo $this->url(array('controller' => 'kosarica', 'action' => 'pregled')) ?>'">Nadaljuj z nakupom</button>
</div>